/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * UI.java
 *
 * Created on Apr 19, 2009, 12:08:37 PM
 */

package gui;

import youtubeJava.Browser;
import youtubeJava.FeedManager;

/**
 *
 * @author Mark
 */
public class UI extends javax.swing.JFrame {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
     * 
     * 
     * 
     */
    FeedManager feed1 = new FeedManager("http://gdata.youtube.com/feeds/api/standardfeeds/recently_featured");



    /** Creates new form UI */
    public UI() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {

        JBtopRated = new javax.swing.JButton();
        JBRecommended = new javax.swing.JButton();
        JBMostViewed = new javax.swing.JButton();
        JBHelp = new javax.swing.JButton();
        JTSearch = new javax.swing.JTextField();
        JBSearch = new javax.swing.JButton();
        JBLaunch = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        JLVideoList = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("YoutubeJava");

        JBtopRated.setText("Top Rated");
        JBtopRated.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBtopRatedActionPerformed(evt);
            }
        });

        JBRecommended.setText("Recommended");
        JBRecommended.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBRecommendedActionPerformed(evt);
            }
        });

        JBMostViewed.setText("Most Viewed");
        JBMostViewed.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBMostViewedActionPerformed(evt);
            }
        });

        JBHelp.setText("Help");
        JBHelp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBHelpActionPerformed(evt);
            }
        });

        JBSearch.setText("Search");
        JBSearch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBSearchActionPerformed(evt);
            }
        });

        JBLaunch.setText("Launch Video");
        JBLaunch.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                JBLaunchActionPerformed(evt);
            }
        });

        JLVideoList.setModel(new javax.swing.AbstractListModel() {
            /**
			 * 
			 */
			private static final long serialVersionUID = 1L;
			String[] strings = feed1.getListValues();
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        JLVideoList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                JLVideoListMouseEntered(evt);
            }
        });
        jScrollPane1.setViewportView(JLVideoList);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(JBtopRated)
                    .addComponent(JBRecommended)
                    .addComponent(JBMostViewed)
                    .addComponent(JBHelp)
                    .addComponent(JTSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(JBSearch)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 87, Short.MAX_VALUE)
                        .addComponent(JBLaunch))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 247, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(JBtopRated)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JBRecommended)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JBMostViewed)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(JBHelp))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 179, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(JBLaunch)
                    .addComponent(JTSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(JBSearch))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


    String videoID[] = new String[25];
    String videoTitles[] = new String[25];
    boolean pressed = false;
        
    

    private void JBtopRatedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBtopRatedActionPerformed
        FeedManager feed1 = new FeedManager("http://gdata.youtube.com/feeds/api/standardfeeds/top_rated");
        for(int i=0;i<25;i++)
        {
            System.out.print("Getting list id number "+i);
            videoID[i] = feed1.getListIDs()[i];
            videoTitles[i] = feed1.getListValues()[i];
        }
        
        JLVideoList.setListData(feed1.getListValues());
        pressed = true;
        
    }//GEN-LAST:event_JBtopRatedActionPerformed

    private void JBRecommendedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBRecommendedActionPerformed
        FeedManager feed1 = new FeedManager("http://gdata.youtube.com/feeds/api/standardfeeds/top_favorites");
        JLVideoList.setListData(feed1.getListValues());
        for(int i=0;i<25;i++)
        {
            System.out.print("Getting list id number "+i);
            videoID[i] = feed1.getListIDs()[i];
            videoTitles[i] = feed1.getListValues()[i];
        }

        JLVideoList.setListData(feed1.getListValues());
        pressed = true;
    }//GEN-LAST:event_JBRecommendedActionPerformed

    private void JBMostViewedActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBMostViewedActionPerformed
        FeedManager feed1 = new FeedManager("http://gdata.youtube.com/feeds/api/standardfeeds/most_viewed");
        JLVideoList.setListData(feed1.getListValues());
        for(int i=0;i<25;i++)
        {
            System.out.print("Getting list id number "+i);
            videoID[i] = feed1.getListIDs()[i];
            videoTitles[i] = feed1.getListValues()[i];
        }

        JLVideoList.setListData(feed1.getListValues());
        pressed = true;
    }//GEN-LAST:event_JBMostViewedActionPerformed


    private void JBLaunchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBLaunchActionPerformed
       String selectedVideo = videoID[JLVideoList.getSelectedIndex()];
       new Browser("http://www.d1004748.cp.blacknight.com/phpsandbox/youtube.php?id="+selectedVideo, videoTitles[JLVideoList.getSelectedIndex()]);
    }//GEN-LAST:event_JBLaunchActionPerformed

    private void JLVideoListMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_JLVideoListMouseEntered
        if(pressed==false)
        {
            for(int i=0;i<25;i++)
            {
                videoID[i] = feed1.getListIDs()[i];
                videoTitles[i] = feed1.getListValues()[i];
            }

        }
    }//GEN-LAST:event_JLVideoListMouseEntered

    private void JBSearchActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBSearchActionPerformed
        //http://gdata.youtube.com/feeds/api/videos?q=football
        if(JTSearch.getText()==null)
            System.out.println("\n\n\n\n\n\nEmpty Text Field");
        FeedManager feed1 = new FeedManager("http://gdata.youtube.com/feeds/api/videos?q="+JTSearch.getText());
        JLVideoList.setListData(feed1.getListValues());
        for(int i=0;i<25;i++)
        {
            System.out.print("Getting list id number "+i);
            videoID[i] = feed1.getListIDs()[i];
        }

        JLVideoList.setListData(feed1.getListValues());
        pressed = true;
    }//GEN-LAST:event_JBSearchActionPerformed

    private void JBHelpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_JBHelpActionPerformed
        new Help().setVisible(true);
    }//GEN-LAST:event_JBHelpActionPerformed
    /**
    * @param args the command line arguments
    */
   

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton JBHelp;
    private javax.swing.JButton JBLaunch;
    private javax.swing.JButton JBMostViewed;
    private javax.swing.JButton JBRecommended;
    private javax.swing.JButton JBSearch;
    private javax.swing.JButton JBtopRated;
    private javax.swing.JList JLVideoList;
    private javax.swing.JTextField JTSearch;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
